package com.hugoo.form.xo;

import com.hugoo.core.UnAuthz;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Lovelock.Chan
 */
public class XForm extends XDBL {
    
    private String id;
    private XForms xfm;
    private String location;
    private String tpl, authz;
    //基本表单操作 码注册 其中：load为加载数据资源，list:加载列表数据，Insert为新增操作，EDIT为更新操作,在DROP为删除操作，VIEW为加载实例
    private String load, list, insert, edit, drop, view;
    private Map<String, XHandle> xHandleMap = new HashMap();
    private boolean unAuthz = false;
    
    public void addXHandle(XHandle xHandle) {
        xHandle.setxForm(this);
        xHandleMap.put(xHandle.getId().toUpperCase(), xHandle);
        if (unAuthz || "none".equalsIgnoreCase(xHandle.getAuthz())) {
            UnAuthz.putXHandle(this, xHandle);
        }
    }
    
    public XForms getXfm() {
        return xfm;
    }
    
    public void setXfm(XForms xfm) {
        this.xfm = xfm;
    }
    
    public XHandle getXHandle(String key) {
        if ("load".equalsIgnoreCase(key)) {
            key = load;
        } else if ("list".equalsIgnoreCase(key)) {
            key = list;
        } else if ("insert".equalsIgnoreCase(key)) {
            key = insert;
        } else if ("edit".equalsIgnoreCase(key)) {
            key = edit;
        } else if ("drop".equalsIgnoreCase(key)) {
            key = drop;
        } else if ("view".equalsIgnoreCase(key)) {
            key = view;
        }
        return xHandleMap.get(key.toUpperCase());
    }
    
    public XHandle getListHandle() {
        return xHandleMap.get(list.toUpperCase());
    }
    
    public void setAuthz(String authz) {
        if ("none".equalsIgnoreCase(authz)) {
            this.unAuthz = true;
        }
        this.authz = authz;
    }
    
    public Map<String, XHandle> getxHandleMap() {
        return xHandleMap;
    }
    
    public void setxHandleMap(Map<String, XHandle> xHandleMap) {
        this.xHandleMap = xHandleMap;
    }
    
    public String getLocation() {
        return location;
    }
    
    public void setLocation(String location) {
        this.location = location;
    }
    
    public String getLoad() {
        return load;
    }
    
    public void setLoad(String load) {
        this.load = load;
    }
    
    public String getList() {
        return list;
    }
    
    public void setList(String list) {
        this.list = list;
    }
    
    public String getInsert() {
        return insert;
    }
    
    public void setInsert(String insert) {
        this.insert = insert;
    }
    
    public String getEdit() {
        return edit;
    }
    
    public void setEdit(String edit) {
        this.edit = edit;
    }
    
    public String getDrop() {
        return drop;
    }
    
    public void setDrop(String drop) {
        this.drop = drop;
    }
    
    public String getView() {
        return view;
    }
    
    public void setView(String view) {
        this.view = view;
    }
    
    public String getTpl() {
        return tpl;
    }
    
    public void setTpl(String tpl) {
        this.tpl = tpl;
    }
    
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    @Override
    public String getParentDbl() {
        return this.getXfm().getDbl();
    }
}
